#include <tsin/library/BulletLineRouter.hpp>

#include <tsin/runtime/BulletRuntime.hpp>
#include <tsin/library/BulletTranslateEvent.hpp>

#include <cstring>
#define _USE_MATH_DEFINES
#include <cmath>

#include <tsin/util/MemCheck.hpp>
using namespace tsin;

void BulletLineRouter::init(float speed, float dangle, float starting)
{
        this->speed = speed;
        this->dangle = dangle;
        this->starting = starting;
}

DynamicObject *BulletLineRouter::copy()
{
        return DynamicObject::copy(new BulletLineRouter);
}

void BulletLineRouter::reinit()
{
        float arg1 = arguments[0]->getFloat();
        float arg2 = arguments[1]->getFloatInRad();
        float arg3 = arguments[2]->getFloat();

        switch(nrArguments) {
        case 1:
                if (strcmp(desp, "N") == 0)
                        init(arg1);
                break;
        case 2:
                if (strcmp(desp, "NN") == 0)
                        init(arg1, arg2);
                break;
        case 3:
                if (strcmp(desp, "NNN") == 0)
                        init(arg1, arg2, arg3);
                break;
        }
}

void BulletLineRouter::reset()
{
}

void BulletLineRouter::route(BulletRuntime *bullet)
{
        BulletTranslateEvent *event = new BulletTranslateEvent;
        event->init(speed, dangle, starting);
        if (!bullet->addBulletEvent(event))
                delete event;
}

DynamicObject *bindLineRouter()
{
        return new BulletLineRouter;
}
